/**
 * 
 */
package org.t2.backstage.module.difchannel.mz.service;

import org.gaming.ruler.lifecycle.Lifecycle;
import org.gaming.service.service.redis.OneToOneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.t2.backstage.foundation.starting.ApplicationSettings;
import org.t2.backstage.module.difchannel.mz.model.MzSetting;

/**
 * 
 */
@Service
public class MzSettingService extends OneToOneService<MzSetting> implements Lifecycle {

	@Autowired
	private ApplicationSettings applicationSettings;
	
	@Override
	public void start() throws Exception {
		if(!applicationSettings.isServerBackstageMain()) {
			return;
		}
		MzSetting setting = this.repository().getByKeys(1L);
		if(setting != null) {
			return;
		}
		setting = new MzSetting();
		setting.setId(1L);
		this.insert(setting);
	}
	
	public MzSetting getSetting() {
		return this.repository().getByKeys(1L);
	}

	@Override
	protected String namespace() {
		return "difchannel";
	}
}
